﻿// See https://aka.ms/new-console-template for more information
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;

Console.WriteLine("Hello, World!");


string jsCode = @"
function encrypt(pwd) {
            console.log(pwd)
            const key = CryptoJS.enc.Latin1.parse(""thanks,pig4cloud"")
            var iv = key

            var encrypted = CryptoJS.AES.encrypt(pwd, key, {
                iv: iv,
                mode: CryptoJS.mode.CFB,
                padding: CryptoJS.pad.NoPadding
            })
            return encrypted.toString()
        }";

using (var engine = new V8ScriptEngine())
{
    var code = File.ReadAllText("cryptojs.js");
    engine.Execute(code);
    engine.Execute(jsCode);

    var pwd = "123456";
    var encrypted = engine.Script.encrypt(pwd);
    Console.WriteLine(encrypted);
}

Console.ReadLine();
